<?php

namespace App\Services\Validator;

class StudentInfo
{
	public $collegeEntries = ['2013', '2014', '2015', '2016'];

	public $collegeNumberArr = ['517', '1620'];

	public function college($attribute, $value, $parameters, $validator)
	{
		$colleges = ['石河子大学商学院', '石河子大学科技学院'];

		return in_array($value, $colleges);
	}

	public function professional($attribute, $value, $parameters, $validator)
	{
		$professionals = [
			'电子商务', '物流管理', '统计', '金融', '人力资源', '审计',
			'公共事业管理', '工商管理', '法学', '国际贸易',
		];

		return in_array($value, $professionals);
	}

	public function studentId($attribute, $value, $parameters, $validator)
	{
		if (strlen($value) === 10 || strlen($value) === 11) {
			$collegeEntry;
			$collegesCode;
			if (strlen($value) === 10) {
				$collegeEntry = substr($value, 0, 4);
				$collegesCode = substr($value, 4, 3);
			}

			if (strlen($value) === 11) {
				$collegeEntry = substr($value, 0, 4);
				$collegesCode = substr($value, 4, 4);
			}
			
			if (in_array($collegeEntry, $this->collegeEntries) && in_array($collegesCode, $this->collegeNumberArr)) {
				return true;
			}else{
				return false;
			}
		}else{
			return false;
		}
	}

	public function collegeEntry($attribute, $value, $parameters, $validator)
	{
		return in_array($value, $this->collegeEntries);
	}
}